package com.wwdx.controller.admin;

import com.wwdx.controller.base.BaseController;
import com.wwdx.model.WvirtualModel;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.Date;

/**
 * @author liguoliang
 */
@Controller
@RequestMapping("/system/virtual")
public class WwdxVirtualController extends BaseController{

    @RequestMapping("/recharge_index")
    public ModelAndView rechargeIndex() {
        return new ModelAndView();
    }

    @RequestMapping("/spending_index")
    public ModelAndView spendingIndex() {
        return new ModelAndView();
    }

    /**
     * 虚拟币列表
     */
    @RequestMapping("/list")
    public ModelAndView list(@RequestParam(value = "page", defaultValue = "1") Integer page,
                             @RequestParam(value = "rows",defaultValue = "10") Integer rows) {
        ModelAndView mav = new ModelAndView();
        mav.addObject("listSize", wvirtualService.selectModelCount());
        mav.addObject("list",  wvirtualService.selectModelList(page,rows));
        return mav;
    }

    /**
     * 新增
     */
    @RequestMapping("/create")
    public ModelAndView create() {
        return new ModelAndView();
    }

    /**
     * 新增保存
     */
    @RequestMapping("/save")
    public Object save(WvirtualModel model) {
        model.setCreateTime(new Date());
        wvirtualService.save(model);
        return "redirect:/system/virtual/list";
    }

    /**
     * 修改
     */
    @RequestMapping("/edit")
    public ModelAndView edit(Integer id) {
        ModelAndView mav = new ModelAndView();
        mav.addObject("model",wvirtualService.getById(id));
        return mav;
    }

    /**
     * 修改保存
     */
    @RequestMapping("/update")
    public Object update(WvirtualModel model) {
        model.setModifyTime(new Date());
        wvirtualService.update(model);
        return "redirect:/system/virtual/list";
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresRoles("super")
    public String delete(Integer id) {
        wvirtualService.delete(wvirtualService.getById(id));
        return "redirect:/system/virtual/list";
    }
}